// 引入发送请求的函数对象
import request from "@/utils/request";
// 引入响应返回值的数据类型
import type {
  CategoryListModel,
  SubmitCategoryModel,
  ChangeCategoryModel,
} from "@/types";

// 定义请求地址的枚举
enum Api {
  GetCategory1List = "/admin/product/getCategory1",
  GetCategory2List = "/admin/product/getCategory2",
  GetCategory3List = "/admin/product/getCategory3",
  DelCategory1List = "/admin/product/removeCategory1",
  DelCategory2List = "/admin/product/removeCategory2",
  DelCategory3List = "/admin/product/removeCategory3",
  PostCategory1List = "/admin/product/saveCategory1",
  PostCategory2List = "/admin/product/saveCategory2",
  PostCategory3List = "/admin/product/saveCategory3",
  PutCategory1List = "/admin/product/updateeCategory1",
  PutCategory2List = "/admin/product/updateeCategory2",
  PutCategory3List = "/admin/product/updateeCategory3",
}

/**
 * 获取一级分类
 * @returns CategoryListModel
 */
export const getCategory1ListApi = () => {
  return request.get<any, CategoryListModel>(Api.GetCategory1List);
};

/**
 * 获取二级分类
 * @param category1Id 一级分类id
 * @returns CategoryListModel
 */
export const getCategory2ListApi = (category1Id: number) => {
  return request.get<any, CategoryListModel>(
    Api.GetCategory2List + `/${category1Id}`
  );
};

/**
 * 获取三级分类
 * @param category2Id 二级分类id
 * @returns CategoryListModel
 */
export const getCategory3ListApi = (category2Id: number) => {
  return request.get<any, CategoryListModel>(
    Api.GetCategory3List + `/${category2Id}`
  );
};

/**
 * 添加一级分类
 * @param baseCategory1 添加一级分类数据
 * @returns ChangeCategoryModel
 */
export const postCategory1ListApi = (baseCategory1: SubmitCategoryModel) => {
  return request.post<any, CategoryListModel>(
    Api.PostCategory1List,
    baseCategory1
  );
};

/**
 * 添加二级分类
 * @param baseCategory2 添加二级分类数据
 * @returns ChangeCategoryModel
 */
export const postCategory2ListApi = (baseCategory2: SubmitCategoryModel) => {
  return request.post<any, CategoryListModel>(
    Api.PostCategory2List,
    baseCategory2
  );
};

/**
 * 添加三级分类
 * @param baseCategory3 添加三级分类数据
 * @returns ChangeCategoryModel
 */
export const postCategory3ListApi = (baseCategory3: SubmitCategoryModel) => {
  return request.post<any, CategoryListModel>(
    Api.PostCategory3List,
    baseCategory3
  );
};

/**
 * 修改一级分类
 * @param baseCategory1 修改一级分类数据
 * @returns ChangeCategoryModel
 */
export const putCategory1ListApi = (baseCategory1: SubmitCategoryModel) => {
  return request.put<any, CategoryListModel>(
    Api.PutCategory1List,
    baseCategory1
  );
};

/**
 * 修改二级分类
 * @param baseCategory2 修改二级分类数据
 * @returns ChangeCategoryModel
 */
export const putCategory2ListApi = (baseCategory2: SubmitCategoryModel) => {
  return request.put<any, CategoryListModel>(
    Api.PutCategory2List,
    baseCategory2
  );
};

/**
 * 修改三级分类
 * @param baseCategory3 修改三级分类数据
 * @returns ChangeCategoryModel
 */
export const putCategory3ListApi = (baseCategory3: SubmitCategoryModel) => {
  return request.put<any, CategoryListModel>(
    Api.PutCategory3List,
    baseCategory3
  );
};

/**
 * 删除一级分类
 * @param category1Id 一级分类id
 * @returns ChangeCategoryModel
 */
export const delCategory1ListApi = (category1Id: number) => {
  return request.delete<any, ChangeCategoryModel>(
    Api.DelCategory1List + `/${category1Id}`
  );
};
/**
 * 删除二级分类
 * @param category1Id 二级分类id
 * @returns ChangeCategoryModel
 */
export const delCategory2ListApi = (category2Id: number) => {
  return request.delete<any, ChangeCategoryModel>(
    Api.DelCategory2List + `/${category2Id}`
  );
};

/**
 * 删除三级分类
 * @param category3Id 三级分类id
 * @returns ChangeCategoryModel
 */
export const delCategory3ListApi = (category3Id: number) => {
  return request.delete<any, ChangeCategoryModel>(
    Api.DelCategory3List + `/${category3Id}`
  );
};
